package config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

public class SpringConfig {
    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource) {
//        创建工厂
        SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
        sessionFactoryBean.setDataSource(dataSource);
        sessionFactoryBean.setTypeAliasesPackage("admin");
        return sessionFactoryBean;
    }
@Bean
    public MapperScannerConfigurer mapperScannerConfigurer() {
//        创建映射器
        MapperScannerConfigurer configurer = new MapperScannerConfigurer();
        configurer.setBasePackage("mapper");
        return configurer;
    }

}
